/* eslint-disable @typescript-eslint/no-explicit-any */
import { reactive } from 'vue';
import Variables from '../constant/vars';
import { IGlobalConfig } from '../interface';

/**
 * @description 全局配置控制器
 * @export
 * @class GlobalConfigController
 */
export class GlobalConfigController {
  /**
   * @description 全局配置
   * @private
   * @type {IGlobalConfig}
   * @memberof GlobalConfigController
   */
  private config: IGlobalConfig = reactive({} as IGlobalConfig);

  /**
   * Creates an instance of GlobalConfigController.
   * @param {IGlobalConfig} config
   * @memberof GlobalConfigController
   */
  constructor(config: IGlobalConfig) {
    this.setConfig(config);
  }

  /**
   * @description 设置全局配置
   * @param {IGlobalConfig} config
   * @memberof GlobalConfigController
   */
  setConfig(config: Record<string, any>): void {
    const keys = Object.keys(Variables.default);
    Object.keys(config).forEach(key => {
      if (keys.includes(key)) (this.config as any)[key] = config[key];
    });
  }

  /**
   * @description 获取全局配置
   * @returns {*}  {IGlobalConfig}
   * @memberof GlobalConfigController
   */
  getConfig(): IGlobalConfig {
    return this.config;
  }

  /**
   * @description 销毁
   * @memberof GlobalConfigController
   */
  destory(): void {}
}
